﻿using DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAO
{
    public class TaiKhoan_DAO
    {
        public static bool KiemTraNguoiDung(string id, string pass)
        {
            string sql = "select * from TAIKHOAN where TenTaiKhoan='" + id + "' and MatKhau='" + pass + "'";
            DataTable dt = DataAccess.executeQuery(sql);
            if (dt.Rows.Count != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static DataTable SelectAll()
        {
            string sql = "select * from TAIKHOAN";
            return DataAccess.executeQuery(sql);
        }

        public static TaiKhoan_DTO SelectByTen(string ten)
        {
            string sql = "select * from TAIKHOAN where TenTaiKhoan = '" + ten + "'";
            DataTable dt = DataAccess.executeQuery(sql);
            TaiKhoan_DTO dto = new TaiKhoan_DTO();
            dto.TenTaiKhoan = Convert.ToString(dt.Rows[0]["TenTaiKhoan"]);
            dto.MatKhau = Convert.ToString(dt.Rows[0]["MatKhau"]);
            dto.PhanQuyen = Convert.ToString(dt.Rows[0]["PhanQuyen"]);
            return dto;
        }
        public static void Insert(TaiKhoan_DTO dto)
        {
            string sql = "Insert INTO TAIKHOAN (TenTaiKhoan, MatKhau, PhanQuyen)" +
                            "VALUES ('" + dto.TenTaiKhoan +
                                     "','" + dto.MatKhau+
                                     "','" + dto.PhanQuyen + "')";

            DataAccess.executeNonQuery(sql);
        }
        public static void Update(TaiKhoan_DTO dto)
        {
            string sql = "Update TAIKHOAN set MatKhau=('" + dto.MatKhau +
                                            "'),PhanQuyen=('" + dto.PhanQuyen +
                                            "') where TenTaiKhoan = '" + dto.TenTaiKhoan + "'";

            DataAccess.executeNonQuery(sql);
        }
        public static void Delete(string ten)
        {
            string sql = "Delete from TAIKHOAN where TenTaiKhoan = '" + ten + "'";
            DataAccess.executeNonQuery(sql);
        }
    }
}
